package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.LiftHistory;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/2/25
 *
 * 升降机详情历史数据适配器
 */

public class LiftDataHistoryListAdapter extends RecyclerAdapter<LiftHistory, LiftDataHistoryListAdapter.LiftHistoryListViewHolder> {

    public LiftDataHistoryListAdapter(Context context, List<LiftHistory> dataList) {
        super(context, dataList);
    }

    @Override
    public LiftHistoryListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_lift_data_list_history, null);
        return new LiftHistoryListViewHolder(view);
    }

    @Override
    public void onBindViewHolder(LiftHistoryListViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class LiftHistoryListViewHolder extends RecyclerAdapter.BaseViewHolder<LiftHistory>{
        @BindView(R.id.create_time_tv)
        HXTextView createTimeTv;
        @BindView(R.id.lift_warning_type_tv)
        HXTextView liftWarningTypeTv;
        @BindView(R.id.lift_alarm_type_tv)
        HXTextView liftAlarmTypeTv;
        @BindView(R.id.lift_abmormal_type_tv)
        HXTextView liftAbmormalTypeTv;
        @BindView(R.id.lift_normal_type_tv)
        HXTextView liftNormalTypeTv;

        public LiftHistoryListViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            final LiftHistory liftHistory = dataList.get(position);
            createTimeTv.setText(liftHistory.getAcquisitionTime());
            if(liftHistory.getWarningStatus() == 1){//	是否预警，0否，1是
                liftWarningTypeTv.setVisibility(View.VISIBLE);
                if(liftNormalTypeTv.getVisibility() == View.VISIBLE){
                    liftNormalTypeTv.setVisibility(View.GONE);
                }
            }else {
                liftWarningTypeTv.setVisibility(View.GONE);
            }
            if(liftHistory.getAlarmStatus() == 1){//	是否报警，0否，1是
                liftAlarmTypeTv.setVisibility(View.VISIBLE);
                if(liftNormalTypeTv.getVisibility() == View.VISIBLE){
                    liftNormalTypeTv.setVisibility(View.GONE);
                }
            }else {
                liftAlarmTypeTv.setVisibility(View.GONE);
            }
            if(liftHistory.getAbnormalStatus() == 1){//	是否异常，0-正常，1-异常
                liftAbmormalTypeTv.setVisibility(View.VISIBLE);
                if(liftNormalTypeTv.getVisibility() == View.VISIBLE){
                    liftNormalTypeTv.setVisibility(View.GONE);
                }
            }else {
                liftAbmormalTypeTv.setVisibility(View.GONE);
            }
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClick(liftHistory);
                }
            });
        }
    }
}
